package org.example.core.Service.impl;

import org.example.core.Mapper.UserResultMapper;
import org.example.core.Service.UserFundRecordService;
import org.example.core.Service.UserResultService;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.core.pojo.UserResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cx
 * @since 2025-04-05
 */
@Service
@Transactional
public class UserResultServiceImpl extends ServiceImpl<UserResultMapper, UserResult> implements UserResultService {

    @Autowired
    StringRedisTemplate stringRedisTemplate;
    @Autowired
    UserFundRecordService userFundRecordService;

    @Override
    public void saveList(List<String> list, Long UserId) {
        List<UserResult> collect = list.stream().map(item -> {
                    UserResult userResult = new UserResult();
                    userResult.setUserId(UserId);
                    userResult.setUrl(item);
                    userResult.setCollect(0);
                    return userResult;
                }
        ).collect(Collectors.toList());
        this.saveBatch(collect);
        userFundRecordService.pointDeduction(UserId,collect.size());
    }
}
